package com.example.spark.controller;

import com.example.spark.entity.Publicize;
import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.impl.PublicizeServiceImpl;
import liquibase.pro.packaged.L;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@CrossOrigin
@RestController
@RequestMapping("/publicize")
public class PublicizeController {

    @Autowired
    private PublicizeServiceImpl publicizeService;

    // 新增招新宣传信息
    @PostMapping (value = "/savePublicize")
    public CommonResult addPublicize(@RequestBody Publicize publicize){
        CommonResult commonResult = publicizeService.addPublicize(publicize);
        return commonResult;
    }

    @PutMapping(value = "/updatePhoto/{id}")
    public CommonResult updatePhoto(@RequestParam MultipartFile photo, @PathVariable Long id) throws Exception {
        CommonResult commonResult = publicizeService.updatePhoto(photo, id);
        return commonResult;
    }

    // 修改招新宣传信息
    @PutMapping(value = "/updatePublicize")
    public CommonResult updatePublicize(@RequestBody Publicize publicize)  {
        CommonResult commonResult = publicizeService.updatePublicize(publicize);
        return commonResult;
    }

    // 查找招新宣传信息
    @GetMapping(value = "/selectPublicize")
    public CommonResult getPublicize(@RequestParam String name){
        CommonResult commonResult = publicizeService.getPublicize(name);
        return commonResult;
    }



}
